#include "../source/server.hpp"

void OnConnected(const PtrConnection &conn)
{
    DBG_LOG("NEW CONNECTION: %p", conn.get());
}
void OnClosed(const PtrConnection &conn)
{
    DBG_LOG("CLOSE CONNECTION: %p", conn.get());
}

void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    DBG_LOG("当前读位置地址：%s", buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadableSize());
    std::string str = "我收到了你发送的消息";
    conn->Send(str.c_str(), str.size());
    conn->Shutdown(); // 通信一次直接关闭连接
}

int main()
{
    TcpServer server(8500);
    server.SetThreadCount(2);
    // server.EnableInactiveRelease(10);
    server.SetClosedCallBack(OnClosed);
    server.SetConnectedCallBack(OnConnected);
    server.SetMessageCallBack(OnMessage);
    server.Start();
    return 0;
}